import Ember from 'ember';
import { moduleForModel, test } from 'ember-qunit';

moduleForModel('person', 'Unit | Model | person', {
  // Specify the other units that are required for this test.
  needs: ['model:role']
});


test('changedAttributes', function(assert) {
  var store = this.store();

  Ember.run(function() {

    store.push("role", {id: 1, name: "n1"});
    store.push("person", {id: 1, email: "email1", roles: ["1"]});
    var hasrole = store.peekRecord("person", 1);

    assert.equal(hasrole.get('roles').length, 1);
    hasrole.get('roles').removeObject(store.peekRecord("role", 1)); //remove one role

    assert.equal(hasrole.get('roles').length, 0);

    assert.notOk(hasrole.changedAttributes().role); //关系变化，不会反映到changedAttributes里面去。
    assert.ok(hasrole.hasDirtyAttributes); //关系的变化，可以被dirty检测到。
    hasrole.set("email", "email");
    assert.ok(hasrole.changedAttributes().email);
  });
});
